package seekting.demo2017.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;

import com.seekting.demo_lib.MainActivity;

import java.io.IOException;

import seekting.demo2017.AppEnv;
import seekting.demo2017.activity.util.BitmapSaver;

/**
 * Created by seekting on 17-5-18.
 */

public class BitmapCompressActivity extends Activity {

    public static final boolean DEBUG = AppEnv.bAppdebug;
    public static final String TAG = BitmapCompressActivity.class.getSimpleName();

    static {

        MainActivity.TITLE_MAP.put(BitmapCompressActivity.class, "");
        MainActivity.DESC_MAP.put(BitmapCompressActivity.class, "");
    }

    private int count = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bitmap bitmap = null;
        try {
            bitmap = BitmapFactory.decodeStream(getAssets().open("comp_1"));
//            bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 10, bitmap.getHeight() / 10, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        BitmapSaver btimapSaver = new BitmapSaver(bitmap, new BitmapSaver.BitmapSaverCallBack() {
            @Override
            public void onSaveBegin() {
                if (DEBUG) {
                    Log.d(TAG, "onSaveBegin.");
                }

            }

            @Override
            public void onSaveProgress(int progress) {
                if (DEBUG) {
                    Log.d(TAG, "onSaveProgress.progress" + progress);
                }

            }

            @Override
            public void onSaveEnd() {
                if (DEBUG) {
                    Log.d(TAG, "onSaveEnd.");
                }

            }

            @Override
            public void onSaveError(Throwable t) {
                if (DEBUG) {
                    Log.e(TAG, "onSaveError.", t);
                }

            }
        }, null);
        String path = getFilesDir() + "/t.jpg";
        btimapSaver.execute(Bitmap.CompressFormat.JPEG, 100, path);


    }
}
